﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Text;

namespace Study
{
    public partial class Lemon : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string url = "http://onecostexternal.us.dell.com/ExternalPO/PO.aspx?qRegion=C10000&qPONum=40201125&qReqNum=2281933";
            string username = "anna_zhang@wistron.com";
            string pwd = "Best@123";
            string baidu = "http://www.baidu.com";
            WebClient wc=new WebClient();

            //wc.UseDefaultCredentials = true;
            CredentialCache myCache = new CredentialCache();

            NetworkCredential nc = new NetworkCredential(username, pwd);
            myCache.Add(new Uri(url), "Basic", nc);
            wc.Credentials = myCache;
            wc.Headers.Add("WWW-Authenticate: Basic realm=\"" + Base64("anna_zhang@wistron.com/Best@123") + "\"");
            wc.Encoding = Encoding.UTF8;
            string s = wc.DownloadString(baidu);
            

        }

        public static string Base64(string s)
        {
            byte[] bytes = Encoding.Default.GetBytes("要转换的字符");
            string str = Convert.ToBase64String(bytes);
            return str;
        }
    }
}